<template>
  <div class="login-container">
    <div class="lc-tit">
      <h4><slot name="dl">登录</slot></h4>
      <slot name="zs">
        <span
          ><slot name="p-login">手机验证登录</slot>
          <slot name="p-icon"><img src="./phone.png" alt=""/></slot
        ></span>
      </slot>
    </div>
    <div class="lc-content">
      <input type="text" placeholder="请输入手机号" v-model="username" />
      <input type="password" placeholder="请输入密码" v-model="password" />
      <!-- <slot name="other"></slot> -->
      <slot name="re-psw"> </slot>
      <div class="yzm">
        <span>验证码</span>
        <img src="./yzm.png" alt="" />
        <span>看不清换一张</span>
      </div>
      <slot name="ph-yzm"> </slot>
      <div class="auto-login">
        <slot name="agree-login">
          <van-checkbox
            v-model="checked"
            shape="square"
            checked-color="#f08200"
            class="at-check"
            >自动登录</van-checkbox
          >
          <a href="#">忘记密码?</a>
        </slot>
      </div>
      <slot name="lgzc"
        ><div class="btn">
          <span @click="toLogin">登录</span>
          <router-link to="/register" tag="span">会员注册</router-link>
        </div></slot
      >

      <slot name="bt">
        <p class="ts">提示：未注册用户将直接注册成为礼拜五用户</p>
        <p class="cp">用合作网站登录</p>
        <div class="login-way">
          <img src="./wechat.png" alt="" />
          <img src="./qq.png" alt="" /></div
      ></slot>
    </div>
  </div>
</template>

<script>
import axios from 'axios';
export default {
  name: 'loginContainer',
  data() {
    return {
      username: '',
      password: '',
      checked: false,
      sms: '',
    };
  },
  methods: {
    toLogin() {
      let obj = JSON.stringify({ phone: this.username, pwd: this.password });
      axios({
        method: 'post',
        url: 'small/user/v1/login',
        data: obj,
        headers: {
          'Content-Type': 'application/json',
        },
      }).then((res) => {
        if (res.data.status == '0000') {
          localStorage.setItem('sessionId', res.data.result.sessionId);
          localStorage.setItem('userId', res.data.result.userId);
          this.$router.replace('/');
        } else {
          alert('账号密码输入有误');
        }
      });
    },
  },
};
</script>

<style scoped>
.zs {
  cursor: pointer;
}
.login-container {
  width: 387px;
  height: 500px;
  background-color: #fff;
  padding: 30px 42px;
}
.login-container h4 {
  font-size: 24px;
  color: #666;
}
.lc-tit {
  display: flex;
  width: 100%;
  justify-content: space-between;
}
.lc-tit span {
  color: #498e3d;
  font-size: 16px;
}
.lc-tit img {
  vertical-align: -2px;
  margin-left: 5px;
}

input {
  height: 44px;
  width: 360px;
  border: 1px solid #d3d3d3;
  padding-left: 12px;
  margin-top: 20px;
}
.yzm {
  height: 46px;
  margin-top: 20px;
  margin-bottom: 20px;
  /* outline: 1px solid red; */
  box-sizing: border-box;
  display: flex;
}
.yzm span:nth-child(1) {
  width: 110px;
  padding: 10px 20px;
  box-sizing: border-box;
  border: 1px solid #e9e9e9;
  color: #999;
  font-size: 16px;
  margin-right: 20px;
}
.yzm span:nth-of-type(2) {
  color: #f08200;
  font-size: 14px;
  margin-left: 20px;
  line-height: 46px;
}
span.change {
  color: #f08200;
  font-size: 14px;
  margin-left: 14px;
  vertical-align: 16px;
}
::v-deep.auto-login {
  display: flex;
  justify-content: space-between;
}
::v-deep.auto-login a {
  font-size: 14px;
  color: #f08200;
  text-decoration: underline;
}
::v-deep span.van-checkbox__label {
  color: #666;
  font-size: 14px;
}
.btn {
  display: flex;
  width: 100%;
  justify-content: space-between;
  margin-top: 20px;
}
.btn span {
  width: 133px;
  height: 46px;
  border-radius: 5px;
  color: #fff;
  text-align: center;
  line-height: 46px;
  font-size: 18px;
  cursor: pointer;
}
.btn span:nth-child(1) {
  background-color: #f08200;
}
.btn span:nth-child(2) {
  background-color: #498e3d;
}
.ts {
  text-align: center;
  margin: 14px auto;
  font-size: 14px;
  color: #999;
}
.cp {
  text-align: center;
  font-size: 16px;
  color: #666;
}
.login-way {
  text-align: center;
  margin-top: 14px;
}
.login-way img {
  cursor: pointer;
}
.login-way img:nth-child(1) {
  margin-right: 20px;
}
</style>
